home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / lcu.zip / MEMCOMP.ASM < prev    next >
Assembly Source File  |  1993-01-04  |  1KB  |  48 lines

  1. COMMENT %
  2. **
  3. **  CompMem - A routine to compare to areas of memory for equality
  4. **  by Richard S. Sadowsky [74017,1670]
  5. **  version 1.0  5/11/88
  6. **  released to the public domain
  7. **  assembled with MASM 5.1
  8. **
  9. %
  10. CODE      SEGMENT BYTE PUBLIC
  11.           ASSUME CS:CODE
  12.  
  13.           PUBLIC CompMem
  14.  
  15. ; function CompMem(var Block1,Block2; Size : Word) : Word
  16. ; return 0 if Block1 and Block2 are equal for Size bytes
  17. ; if not equal, return the position of first non matching byte
  18. ; the first byte is considered to be 1
  19.  
  20. CompMem          PROC FAR
  21.  
  22.        MOV       BX,SP           ; stack frame with BX
  23.        MOV       DX,DS           ; preserve DS in DX
  24.        XOR       AX,AX           ; zero out AX
  25.  
  26.        MOV       CX,SS:[BX+04h]  ; get Size
  27.        JCXZ      Fini            ; if zero then exit
  28.  
  29.        LDS       SI,SS:[BX+0Ah]  ; address of block1 in DS:SI
  30.        LES       DI,SS:[BX+06h]  ; address of block2 in ES:DI
  31.  
  32.        CLD                       ; forward string operations
  33.  
  34.        REPE      CMPSB           ; look for first non match or CX = 0
  35.        JE        Fini            ; equal so exit (o in AX)
  36.  
  37.        MOV       AX,SS:[BX+04h]  ; get size again
  38.        SUB       AX,CX           ; return position of first non match
  39.  
  40. Fini:  MOV       DS,DX           ; restore DS
  41.        RET       0Ah             ; remove params from the stack
  42.  
  43. CompMem          ENDP
  44.  
  45. CODE   ENDS
  46.  
  47.        END
  48.